package com.android.binderserverclient0.workmanager

import android.content.Context
import android.util.Log
import androidx.work.Data
import androidx.work.ListenableWorker
import androidx.work.WorkerParameters
import com.google.common.util.concurrent.ListenableFuture
import java.util.concurrent.Executor
import java.util.concurrent.TimeUnit

class FirstListenableWorker(context: Context, workerParameters: WorkerParameters) : ListenableWorker(context, workerParameters), ListenableFuture<ListenableWorker.Result> {
    override fun startWork(): ListenableFuture<Result> {
        Log.d(TAG,"override fun startWork()")
        return this@FirstListenableWorker
    }

    override fun cancel(mayInterruptIfRunning: Boolean): Boolean = false

    override fun isCancelled(): Boolean {
        return false
    }

    override fun isDone(): Boolean {
        return false
    }

    override fun get(): Result {
        Log.d(TAG,"override fun get()")
        val data = Data.Builder().putInt("hello", 1234).build()
        return Result.success(data)
    }

    override fun get(timeout: Long, unit: TimeUnit?): Result {
        Log.d(TAG,"override fun get(timeout: Long, unit: TimeUnit?)")
        return Result.success()
    }

    override fun addListener(listener: Runnable, executor: Executor) {}

    companion object {
        const val TAG = "FirstListenableWorker"
    }

}